<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除Dom</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }

        th,
        td {
            border: 1px solid #ddd;
            text-align: left;
            padding: 8px;
        }

        th {
            background-color: #4CAF50;
            color: white;
        }

        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
    </style>
</head>

<body>
    <table class="table" id="table">
        <tr>
            <th>书名</th>
            <th>价格</th>
        </tr>

        <tr>
            <td>网页工程实训</td>
            <td>￥199</td>
        <tr>
            <td>C语言工程实训</td>
            <td>￥32</td>
        </tr>
        </tr>


    </table>
    <button id="addRow">增加一行</button>
    <button id="deleteRow2">删除第二行</button>
    <button id="modifyTitle">修改标题</button>
</body>
<script>
    var tableDom = document.getElementById("table");
    var addRowBtnDom = document.getElementById("addRow");
    var deleteRowBtn2Dom = document.getElementById("deleteRow2");
    var modifyTitleBtnDom = document.getElementById("modifyTitle");
    addRowBtnDom.onclick = function () {
        var newTr = document.createElement("tr");
        var newTd1 = document.createElement("td");
        var newTd2 = document.createElement("td");
        newTr.appendChild(newTd1);
        newTr.appendChild(newTd2);
        tableDom.appendChild(newTr);
    };
    deleteRowBtn2Dom.onclick = function () {
        var tr = tableDom.getElementsByTagName("tr");
        tableDom.remove(".table tr:nth-child(2)");
    };
    modifyTitleBtnDom.onclick = function () {
        var ths = tableDom.getElementsByTagName("th");
        ths[0].innerHTML = "书名";
        ths[1].innerHTML = "价格";
    };
</script>

</html>